package Application;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import DbConnection.database;

public class Login 
{
	public boolean isValidUser(String userName, String password)
	{
		boolean validUser = false;
		String query = "SELECT * FROM login where username='" + userName + "' and password = '" + password + "'";
		String retVal = "fail"; 
		try 
		{
			database db = new database();
		    Connection conn = db.getConn();
		    if(conn == null)
		    {
		    	retVal = "fail connection";
		    }
		    else
		    {
		      Statement select = conn.createStatement();
		      ResultSet result = select.executeQuery(query);
		      while (result.next()) 
		      {
		    	retVal = result.getString(1);
		    	validUser = true;
		      }
		      select.close();
		      result.close();
		      conn.close();
		    }
		 } 
		catch(SQLException e) 
		{
		  System.err.println("Mysql Statement Error: " + query);
		  e.printStackTrace();
		}
		return validUser;		
	}
	
}
